package com.fourool.goodsmall.controller;

import com.fourool.goodsmall.common.Result;
import com.fourool.goodsmall.dto.AddressDTO;
import com.fourool.goodsmall.service.GAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/address")
public class AddressController {

    @Autowired
    private GAddressService addressService;

    // 查询列表
    @GetMapping("/list/{pid}")
    public Result list(@PathVariable Integer pid) {
        return addressService.getAddressList(pid);
    }

    // 查询单个
    @GetMapping("/detail/{id}")
    public Result detail(@PathVariable Integer id) {
        return addressService.getAddressDetail(id);
    }

    // 添加
    @PostMapping("/add/{pid}")
    public Result add(@PathVariable Integer pid, @RequestBody AddressDTO dto) {
        return addressService.addAddress(pid, dto);
    }

    // 编辑
    @PutMapping("/edit/{id}")
    public Result edit(@PathVariable Integer id, @RequestBody AddressDTO dto) {
        return addressService.updateAddress(id, dto);
    }

    // 删除
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id) {
        return addressService.deleteAddress(id);
    }
}